package com.mcf.xiaolinju.controller;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mcf.xiaolinju.vo.villageReturn;
import com.mcf.xiaolinju.entity.Village;
import com.mcf.xiaolinju.service.impl.VillageServiceImpl;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Date;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author mcf
 * @since 2021-10-14
 */
@CrossOrigin
@RestController
@RequestMapping("/xiaolinju/village")
public class VillageController {
    @Resource
    VillageServiceImpl villageService;
    //通过小区的主键id查询出小区的信息
    @RequestMapping("/getById")
    public Village getById(Integer id){
        return  villageService.getById(id);
    }
    //通过用户的id查出小区的信息
    @RequestMapping("getByUserId")
    public Village getByUserId(Integer id){
        return  villageService.getByUserId(id);
    }
    //小区的添加
    @RequestMapping("/add")
    public String add(Village village){
        Date date=new Date();
        LocalDateTime ldt=date.toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime();
        village.setCreatetime(ldt);
        if(villageService.save(village)){
            return "添加成功";
        }
        return "添加失败";
    }
    //小区的修改
    @RequestMapping("/update")
    public String update(Integer province,Integer city,Integer area,String adress,String villagename,Integer updateid,Integer id){
        return villageService.update(province,city,area,adress,villagename,updateid,id);
    }
    //小区的删除
    @RequestMapping("/del")
    public String del(int id,int updateid) {
        return  villageService.del(id,updateid);
    }
    //小区的分页查询
    @RequestMapping("/selectpage")
    public Page<villageReturn> selectpage(int pageNo, int pageSize){
        return  villageService.selectpage(new Page<villageReturn>(pageNo,pageSize));
    }
    //小区的批量删除
    @RequestMapping("/manydel")
    public String manydel(int[] id,int updateid){
        return villageService.manydel(id,updateid);
    }
    //小区的模糊查询
    @RequestMapping("/selectdim")
    public Page<villageReturn> selectdim (int pageNo, int pageSize, Integer provinceid,Integer cityid,Integer townid,String villagename ){
        System.out.println(pageNo);
        System.out.println(provinceid);
        System.out.println(villagename);
        return  villageService.selectdim(new Page<villageReturn>(pageNo,pageSize),provinceid,cityid,townid,villagename);
    }
    //根据信息查询小区是否存在
    @RequestMapping("/getvillageid")
    public int getvillageid(String commityname,String region){

        return  villageService.getvillageid(commityname,region);
    }


}
